package semiProject_army.mvc.connection;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

// JNDI를 이용한 DBCP로 부터 Connection을 대여하여 리턴해 주는 클래스
public class ConnectionProvider {
	
	public static Connection getConnection() 
			throws NamingException, SQLException {

		Context context = new InitialContext();
		Context envContext = (Context) context.lookup("java:comp/env");
		
		DataSource ds = (DataSource) envContext.lookup("jdbc/armysemi");
		return ds.getConnection();
	}
	
	public static Connection getConnection0() 
			throws NamingException, SQLException {
		
		Context initCtx = new InitialContext();
		Context envCtx = (Context) initCtx.lookup("java:comp/env");
		DataSource ds = (DataSource) envCtx.lookup("jdbc/armysemi");
		return ds.getConnection();
	}	
}

